<?php
/*------------------------------------------------------------------------------



------------------------------------------------------------------------------*/

/**
* handler to build http response : html/xml/other content, headers etc
* @author Fred Bird <fredbird@fredbird.org>
* @version 
* @todo
*/
class httpResponseBean extends databean {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access public
	* /
	function httpResponseBean() {
		waklib::needclass('datatree');
		$this->content=&new datatree();
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* sends response (headers+content) to client/browser
	* @access public
	* @return bool
	*/
	function sendAll() {
		$this->sendHeaders();
		return $this->sendContent();
	}/**/
	
	/**
	* sends headers to client/browser
	* @access public
	* @return bool
	*/
	function sendHeaders() {
		if ($this->headersSent) return false;
		foreach ($this->headers as $key => $value)
			header("$key: $value");
		$this->headersSent=true;
		return true;
	}/**/
	
	/**
	* sends response content (html page, etc)
	* 
	* @access public
	* @return bool
	*/
	function sendContent() {
		echo $this->get('content');
		return true;
	}
	
	/**
	* sets a header to be sent
	* @param string $key
	* @param string $value
	* @access public
	* @return bool
	*/
	function setHeader($key,$value) {
		$this->headers[$key]=&$value;
		return true;
	}/**/
	
	/**
	* prepare a cookie to be sent
	* @param
	* @param
	* @todo
	* /
	function cookie() {
		
	}/**/
	
	/**
	* sets all response content data at once
	* @param mixed &$data
	* @return bool
	*/
	function setContent(&$data) {
		$this->set('content',$data);
	}
	
	/**
	* sets a content part
	* @param mixed &$content value
	* @param string $key key
	* @return bool
	* /
	function setContentPart(&$content,$key) {
	
	}
	
	/**
	* inserts a new content part
	* @param mixed &$content
	* @param string $key optional
	* @return bool
	* /
	function insertContent(&$content, $key=NULL) {
	
	}
	
	
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var array http response headers, key => value
	*/
	var $headers=array(); // http response headers
	/**
	* @var bool have headers been sent yet ?
	*/
	var $headersSent=false;
	/**
	* @var string content storage
	*/
	var $content;
	/**
	* @var string mime type
	*/
	var $mime; // mime type
	/**
	* @var array cookies to be sent
	*/
	var $cookies=array();
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
